#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main()
{
  int fd = open("log.txt",O_CREAT | O_WRONLY | O_APPEND, 0666);
  
  dup2(fd,1);//将原本打印到显示器的内容，打印到log.txt中：

  printf("hello fd:%d\n",fd);
  fprintf(stdout,"hello fd:%d\n",fd);
  fputs("helle world\n",stdout);
  const char* message = "hello fwrite\n";
  fwrite(message,1,strlen(message),stdout);

  return 0;
}
